<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: Level.php 262 2011-07-23 15:51:14Z beimuaihui $
 */

Zend_Loader::loadClass ( "Baogg_Db_Table" );

//class Permission extends Baogg_Db_Table {
class Dict extends Baogg_Db_Table {
	/**
	 * The default table name 
	 */
	protected $_name;
	protected $_db;
	protected $_primary;
	
	function __construct() {
		
		$this->_name = 'dict';
		$this->primary = $this->_primary = 'dict_id';
		parent::__construct ();
	
	}
	
	function getSame($arr) {
		
		$ret = array ();
		$where ['dict_name'] = $arr ['dict_name'];
		return parent::getSame ( $where );
	
	}
	
	public function getDictList($dict_id, $where = array(), $order = array(), $limit = array()) {
		
		$rs_dict = $this->getOne ( $dict_id );
		
		$model_id = $rs_dict [0] ['model_id'];
		
		if ($rs_dict [0] ['filter']) {
			$where [] = $rs_dict [0] ['filter'];
		}
		
		if (@$rs_dict [0] ['sorting']) {
			$order [] = $rs_dict [0] ['sorting'];
		}
		
		$Model = new Model ();
		$data = $Model->getModelList( $model_id, $where, $order, $limit );
		return $data;
	}
	
	public function getDictCombo($model_id,$filter=array(),$sorting=array(),$limit=array(),$isFilterRequest=true){
		if($isFilterRequest){
			$params=Zend_Controller_Front::getInstance()->getRequest()->getParams();
			$filter=array_merge($params,$filter);
		}
		
		$ret=$this->getDictList($model_id,$filter,$sorting,$limit);
		
		$data=$ret['data'];
		
		$arr=array();
		foreach((array)$data as $v){
			if(!isset($cols)){
				$cols=array_keys($v);
			}
			$arr[]=array($v[$cols[0]],$v[$cols[1]]);
		}
		return $arr;
	}
	
	
}
